package com.acme.bankapp.domain.bank;

/**
 * This class represents bank's client
 * 
 * @author Anton Kotov
 * 
 */
public class Client {

	public Client(String name, Gender gender, Account[] accounts) {
		this.name = name;
		this.gender = gender;
		this.accounts = accounts;
	}

	public Client(String name, Gender gender) {
		this(name, gender, null);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Gender getGender() {
		return gender;
	}

	public void setGender(Gender gender) {
		this.gender = gender;
	}

	public Account[] getAccounts() {
		if (accounts == null)
			return null;

		Account[] newAccounts = new Account[accounts.length];
		System.arraycopy(accounts, 0, newAccounts, 0, accounts.length);
		return newAccounts;
	}

	public Client addAccount(Account account) {
		if (accounts == null) {
			accounts = new Account[1];
			accounts[0] = account;
			return this;
		}

		Account[] newAccounts = new Account[accounts.length + 1];
		System.arraycopy(accounts, 0, newAccounts, 0, accounts.length);
		newAccounts[accounts.length] = account;
		accounts = newAccounts;
		return this;
	}

	public String getClientSalutation() {
		return gender + " " + name;
	}

	public String toString() {
		return getClientSalutation();
	}

	private String name;
	private Gender gender;

	private Account[] accounts;
}
